package com.flyduck.vueshop.product.remote.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.flyduck.vueshop.common.core.utils.BeanUtils;
import com.flyduck.vueshop.product.entity.AppProduct;
import com.flyduck.vueshop.product.mapper.AppProductMapper;
import com.flyduck.vueshop.product.remote.service.RemoteProductService;
import com.flyduck.vueshop.product.vo.RemoteProductRespVO;
import com.flyduck.vueshop.product.vo.RemoteProductUpdateReqVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: vueshop-cloud
 * @description:
 * @author: flyduck
 * @create: 2024-07-15 21:14
 **/
@Service
public class RemoteProductServiceImpl implements RemoteProductService {

    @Resource
    private AppProductMapper appProductMapper;

    @Override
    public RemoteProductRespVO getProductById(Long id) {
        AppProduct appProduct = appProductMapper.selectById(id);
        RemoteProductRespVO remoteProductRespVO = BeanUtils.toBean(appProduct, RemoteProductRespVO.class);
        return remoteProductRespVO;
    }

    @Override
    public List<RemoteProductRespVO> getOnSaleProductList() {
        List<AppProduct> appProductList = appProductMapper.selectList(
                new LambdaQueryWrapper<AppProduct>()
                        .eq(AppProduct::getIsOnSale, true)
        );
        return BeanUtils.toBeanList(appProductList,RemoteProductRespVO.class);
    }

    @Override
    public void batchUpdateProduct(List<RemoteProductUpdateReqVO> remoteProductUpdateReqVOList) {
        List<AppProduct> appProductList = BeanUtils.toBeanList(remoteProductUpdateReqVOList, AppProduct.class);
        appProductMapper.updateBatchById(appProductList);
    }
}
